package toDo.app;

import interfaces.ICentralManager;
import toDo.app.controllers.CentralManagerClickController;
import toDo.app.controllers.CentralManagerResultController;
import toDo.app.models.User;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

public class CentralManager extends ICentralManager {
	private User user;
	private Button loginButton;
	private Button registerButton;
	private TextView statusLabel;
	private CentralManagerClickController cController;
	private CentralManagerResultController rController;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		/*
		 * Central manager shows login form with register option by default.
		 */
		setContentView(R.layout.main);

		loginButton = (Button) findViewById(R.id.mainLoginButton);
		registerButton = (Button) findViewById(R.id.mainRegisterButton);
		statusLabel = (TextView) findViewById(R.id.mainStatusLabel);

		cController = new CentralManagerClickController(this,LoginActivity.class,RegisterActivity.class);
		rController = new CentralManagerResultController(this,ToDoListActivity.class);
		
		loginButton.setOnClickListener(cController);
		registerButton.setOnClickListener(cController);
		statusLabel.setText(R.string.blank);
	}

	/**
	 * this is to get intent data back
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		rController.onActivityResult(requestCode, resultCode, data);
	}
	
	/* (non-Javadoc)
	 * @see toDo.app.ICentralManager#getUser()
	 */
	@Override
	public User getUser(){
		return user;
	}
	
	/* (non-Javadoc)
	 * @see toDo.app.ICentralManager#setUser()
	 */
	@Override
	public void setUser(User user) {
		this.user = user;
	}
	
	/* (non-Javadoc)
	 * @see toDo.app.ICentralManager#setStatusText(String text)
	 */
	@Override
	public void setStatusText(String text){
		statusLabel.setText(text);
	}
}